package com.yuanfeng.job.job;

import com.yuanfeng.commoms.dto.job.ShopSettleAccountInfoDTO;
import com.yuanfeng.commoms.util.DateUtils;
import com.yuanfeng.commoms.util.StringUtils;
import com.yuanfeng.commoms.util.TimeStampUtil;
import com.yuanfeng.job.dto.ForSettleShopInfoDTO;
import com.yuanfeng.job.mapper.SettleAccountsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SettleAccountsServices
 * @Description 账号
 * @Author liulh
 * @Date 2023/5/17 16:14
 * @Version 1.0
 **/
@Service
public class SettleAccountsServices {
    private static final Logger logger = LoggerFactory.getLogger(SettleAccountsServices.class);

    @Resource
    private SettleAccountsMapper settleAccountsMapper;

    @Transactional
    public void settleAccounts(ForSettleShopInfoDTO forSettleShopInfo) {
        try {
            Map<String, String> paraMap = new HashMap<>();

            String shopId = forSettleShopInfo.getShopId();
//            if (forSettleShopInfo.getShopSettlementLastTime() != null) {
//                // 判断是否达到下次结算周期
//                if (DateUtils.getDayByMinusDate(forSettleShopInfo.getShopSettlementLastTime(), new Date()) < forSettleShopInfo.getShopSettlementCycle()) {
//                    return;
//                }
//                // 判断是否距离上次结算有一个月时间
//                if (forSettleShopInfo.getShopSettlementCycle() == 30) {
//                    if (!DateUtils.isMoreThanAMonth(forSettleShopInfo.getShopSettlementLastTime(), new Date())) {
//                        return;
//                    }
//                }
//            }
            logger.info("店铺" + shopId + "更新开始时间：" + TimeStampUtil.getNowDate());

            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
            String dateString = formatter.format(new Date());
            //当前时间
            Date dNow = new Date();
            //设置时间格式
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
            //格式化当前时间
            String end = sdf.format(dNow);
            //获取上次结算时间
            String dBefore = settleAccountsMapper.getBeformDate(shopId, 1);
            if (StringUtils.isEmpty(dBefore)) {
                dBefore = "2019-04-10";
            }
            //格式化上次结算时间
            String start = dBefore + " 00:00:00";
            //end = "2023-12-28 00:00:00";
            Map<String, String> getMap = new HashMap<>();
            getMap.put("start", start);
            getMap.put("end", end);
            getMap.put("shopId", shopId);
            getMap.put("dropShipping", "2");
            //获取单个店铺所有未结算的订单。
            ShopSettleAccountInfoDTO orderSettleAccountOrder = settleAccountsMapper.getSettleAccountOrder(getMap);
            List<String> orderIds = settleAccountsMapper.getSettleAccountOrderId(getMap);
            //获取单个店铺所有未结算的退单
            ShopSettleAccountInfoDTO returnSettleAccountOrder = settleAccountsMapper.getSettleAccountReturn(getMap);
            List<String> returnOrderIds = settleAccountsMapper.getSettleAccountReturnId(getMap);
            if (null == orderSettleAccountOrder) {
                orderSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }
            if (null == returnSettleAccountOrder) {
                returnSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }
            //获取单个店铺普通订单分佣总价
            Double paymentAmounCats = orderSettleAccountOrder.getOrderCommissionFee();

            //获取单个店铺普通订单 退单 分佣总价
            Double refundPaymentAmounCats = returnSettleAccountOrder.getOrderReturnCommissionFee();

            //获取单个店铺的 罚款金额,处罚时间大于72小时
            Double fineMoney = settleAccountsMapper.getFineMoneyByShopId(getMap.get("shopId"));

            //砍价
            //没有订单没有退单
            if (null == orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "1" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                //订单金额，含运费
                paraMap.put("orderPaymentAmount", "0.00");
                //运费
                paraMap.put("osShippingAmount", "0.00");
                Double osOrderReturnAmount = 0.00;
                //退单金额
                paraMap.put("osOrderReturnAmount", osOrderReturnAmount.toString());
                Double commission = 0.00;
                //佣金
                paraMap.put("osCommisAmount", commission.toString());
                Double returnCommission = 0.00;
                //退还佣金
                paraMap.put("osCommisReturnAmount", returnCommission.toString());
                Double osRedpacketAmount = 0.00;
                //红包
                paraMap.put("osRedpacketAmount", osRedpacketAmount.toString());
                Double osRedpacketReturnAmount = 0.00;
                //退还红包
                paraMap.put("osRedpacketReturnAmount", osRedpacketReturnAmount.toString());
                //订单金额(含运费) + 红包金额 - 佣金金额 - 退单金额 + 退还佣金 - 退还红包金额
                Double osAmount = 0.00;
                osAmount = osAmount - fineMoney;
                //应结算金额
                paraMap.put("osAmount", osAmount.toString());
                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                //1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("osState", "1");
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                //结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osOrderType", "1");
                //罚款金额
                paraMap.put("osFineAmount", fineMoney.toString());
                //经销佣金
                paraMap.put("orderDealerCommission", "0");
                //供应商佣金
                paraMap.put("orderSupplyCommission", "0");
                //经销退还佣金
                paraMap.put("returnDealerCommission", "0");
                //供应商退还佣金
                paraMap.put("returnSupplyCommission", "0");
                //会员折扣
                paraMap.put("osBaseMemberDiscount", "0");
                //退还会员折扣
                paraMap.put("osReturnMemberDiscount", "0");
                //推广佣金
                paraMap.put("osTgCommission", "0");
                //分享佣金
                paraMap.put("osFxCommission", "0");

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                //更改罚款表的状态
                Integer two = settleAccountsMapper.updateShopComplainBase(paraMap);
                settleAccountsMapper.updateShopSettlement(shopId);
                logger.info("店铺" + shopId + "没有需要更新订单：" + TimeStampUtil.getNowDate() + "插入成功与否：" + one);
                return;
            }
            //有订单没有退单的情况
            if (null != orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "1" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);
                paraMap.put("osId", osId);
                //订单金额，不含运费
                paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));
                paraMap.put("osShippingAmount", String.valueOf(orderSettleAccountOrder.getOrderShippingFee() - returnSettleAccountOrder.getReturnShippingFee()));//运费

                Double osOrderReturnAmount = 0.00;
                //退单金额
                paraMap.put("osOrderReturnAmount", "0.00");
                //佣金
                paraMap.put("osCommisAmount", paymentAmounCats.toString());

                Double returnCommission = 0.00;
                //退还佣金
                paraMap.put("osCommisReturnAmount", returnCommission.toString());

                Double osRedpacketAmount = orderSettleAccountOrder.getOrderRptPrice();
                //红包
                paraMap.put("osRedpacketAmount", osRedpacketAmount.toString());

                Double osRedpacketReturnAmount = 0.00;
                //退还红包
                paraMap.put("osRedpacketReturnAmount", osRedpacketReturnAmount.toString());
                //会员折扣
                paraMap.put("osBaseMemberDiscount", orderSettleAccountOrder.getBaseMemberDiscount().toString());
                //退还会员折扣
                paraMap.put("osReturnMemberDiscount", "0");
                //推广佣金
                paraMap.put("osTgCommission", orderSettleAccountOrder.getTgCommission().toString());
                //分享佣金
                paraMap.put("osFxCommission", orderSettleAccountOrder.getFxCommission().toString());
                //订单金额(不含运费) + 红包金额 - 佣金金额 - 退单金额 + 退还佣金 - 退还红包金额 - 罚款金额 + 会员折扣 + （运费—退还运费）
                Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount() + osRedpacketAmount - paymentAmounCats
                        - osOrderReturnAmount + returnCommission - osRedpacketReturnAmount - fineMoney + orderSettleAccountOrder.getBaseMemberDiscount()
                        - orderSettleAccountOrder.getTgCommission() - orderSettleAccountOrder.getFxCommission() + (orderSettleAccountOrder.getOrderShippingFee() - returnSettleAccountOrder.getReturnShippingFee());
                //应结算金额
                paraMap.put("osAmount", osAmount.toString());

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                //1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("osState", "1");
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                //结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osOrderType", "1");
                //罚款金额
                paraMap.put("osFineAmount", fineMoney.toString());
                //经销佣金
                paraMap.put("orderDealerCommission", "0");
                //供应商佣金
                paraMap.put("orderSupplyCommission", "0");
                //经销退还佣金
                paraMap.put("returnDealerCommission", "0");
                //供应商退还佣金
                paraMap.put("returnSupplyCommission", "0");

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, String> updateMap = new HashMap<String, String>();
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                updateMap.put("dropShipping", "2");
                Integer two = settleAccountsMapper.updateOrderBaseSettlement(updateMap);
                Integer three = settleAccountsMapper.updateOrderReturnSettlement(updateMap);
                Integer four = settleAccountsMapper.updateShopComplainBase(paraMap);
                settleAccountsMapper.updateShopSettlement(shopId);
                logger.info(orderSettleAccountOrder.toString() + "更新店铺： " + shopId + "  插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two + " 更新退单表结算表个数" + three + "更新结束时间：");
                return;
            }
            //没有订单 有退单
            if (null == orderSettleAccountOrder && null != returnSettleAccountOrder) {
                String osId = dateString + "1" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);
                paraMap.put("osId", osId);
                //订单金额，含运费
                paraMap.put("orderPaymentAmount", "0.00");
                //运费
                paraMap.put("osShippingAmount", "0.00");
                //退单金额
                paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));

                Double commission = 0.00;
                //佣金
                paraMap.put("osCommisAmount", commission.toString());
                //退还佣金
                paraMap.put("osCommisReturnAmount", refundPaymentAmounCats.toString());

                Double osRedpacketAmount = 0.00;
                //红包
                paraMap.put("osRedpacketAmount", osRedpacketAmount.toString());

                Double osRedpacketReturnAmount = returnSettleAccountOrder.getReturnRptCash();
                if (osRedpacketReturnAmount == null) {
                    osRedpacketReturnAmount = 0.00;
                }
                //退还红包
                paraMap.put("osRedpacketReturnAmount", osRedpacketReturnAmount.toString());
                //会员折扣
                paraMap.put("osBaseMemberDiscount", "0");
                //退还会员折扣
                paraMap.put("osReturnMemberDiscount", returnSettleAccountOrder.getReturnMemberDiscount().toString());
                //推广佣金
                paraMap.put("osTgCommission", "0");
                //分享佣金
                paraMap.put("osFxCommission", "0");

                //订单金额(不含运费) + 红包金额 - 佣金金额 - 退单金额 + 退还佣金 - 退还红包金额 - 罚款金额 + 会员折扣 + （运费—退还运费）
                Double osAmount = 0.00 + osRedpacketAmount - returnSettleAccountOrder.getReturnCash()
                        - osRedpacketReturnAmount - fineMoney - refundPaymentAmounCats - returnSettleAccountOrder.getReturnMemberDiscount() + (orderSettleAccountOrder.getOrderShippingFee() - returnSettleAccountOrder.getReturnShippingFee());
                //应结算金额
                paraMap.put("osAmount", osAmount.toString());
                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                //1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("osState", "1");
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                //结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osOrderType", "1");
                //罚款金额
                paraMap.put("osFineAmount", fineMoney.toString());
                //经销佣金
                paraMap.put("orderDealerCommission", "0");
                //供应商佣金
                paraMap.put("orderSupplyCommission", "0");
                //经销退还佣金
                paraMap.put("returnDealerCommission", "0");
                //供应商退还佣金
                paraMap.put("returnSupplyCommission", "0");

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, String> updateMap = new HashMap<String, String>();
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                updateMap.put("dropShipping", "2");
                Integer two = settleAccountsMapper.updateOrderBaseSettlement(updateMap);
                Integer three = settleAccountsMapper.updateOrderReturnSettlement(updateMap);
                Integer four = settleAccountsMapper.updateShopComplainBase(paraMap);
                settleAccountsMapper.updateShopSettlement(shopId);
                logger.info(returnSettleAccountOrder.toString() + "更新店铺：" + shopId + "插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two + " 更新退单表结算表个数" + three + "更新结束时间：" + TimeStampUtil.getNowDate());
                return;
            }
            //有订单有退单
            String osId = dateString + "1" + shopId;
            paraMap.put("osId", osId);
            paraMap.put("osStartDate", start);
            paraMap.put("osEndDate", end);
            //订单金额，含运费
            paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));
            //运费
            paraMap.put("osShippingAmount", String.valueOf(orderSettleAccountOrder.getOrderShippingFee() - returnSettleAccountOrder.getReturnShippingFee()));
            //退单金额
            paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));
            //佣金
            paraMap.put("osCommisAmount", paymentAmounCats.toString());
            //退还佣金
            paraMap.put("osCommisReturnAmount", refundPaymentAmounCats.toString());

            Double osRedpacketAmount = orderSettleAccountOrder.getOrderRptPrice();
            //红包
            paraMap.put("osRedpacketAmount", osRedpacketAmount.toString());

            Double osRedpacketReturnAmount = returnSettleAccountOrder.getReturnRptCash();
            if (osRedpacketReturnAmount == null) {
                osRedpacketReturnAmount = 0.00;
            }
            //退还红包
            paraMap.put("osRedpacketReturnAmount", osRedpacketReturnAmount.toString());
            //会员折扣
            paraMap.put("osBaseMemberDiscount", orderSettleAccountOrder.getBaseMemberDiscount().toString());
            //退还会员折扣
            paraMap.put("osReturnMemberDiscount", returnSettleAccountOrder.getReturnMemberDiscount().toString());
            //推广佣金
            paraMap.put("osTgCommission", orderSettleAccountOrder.getTgCommission().toString());
            //分享佣金
            paraMap.put("osFxCommission", orderSettleAccountOrder.getFxCommission().toString());
            //订单金额(不含运费) - 佣金金额 - 退单金额 + 退还佣金 + （运费—退还运费）
//            Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount() - paymentAmounCats - returnSettleAccountOrder.getReturnCash()
//                    + refundPaymentAmounCats - fineMoney + orderSettleAccountOrder.getBaseMemberDiscount() -
//                    + (orderSettleAccountOrder.getOrderShippingFee() - returnSettleAccountOrder.getReturnShippingFee());
            Double osAmount = 0.00;
            osAmount = osAmount
                    + orderSettleAccountOrder.getOrderPaymentAmount()
                    +orderSettleAccountOrder.getOrderRptPrice()
                    -orderSettleAccountOrder.getOrderCommissionFee()
                    +orderSettleAccountOrder.getBaseMemberDiscount()
                    -returnSettleAccountOrder.getReturnCash()
                    -(null == returnSettleAccountOrder.getReturnRptCash() ? 0.00: returnSettleAccountOrder.getReturnRptCash())
                    -returnSettleAccountOrder.getReturnMemberDiscount()
                    + returnSettleAccountOrder.getOrderReturnCommissionFee()
                    - orderSettleAccountOrder.getTgCommission() - orderSettleAccountOrder.getFxCommission();
            //四舍五入
            BigDecimal bg = new BigDecimal(osAmount);
            osAmount= bg.setScale(2, RoundingMode.HALF_UP).doubleValue();
            //应结算金额
            paraMap.put("osAmount", osAmount.toString());

            paraMap.put("osDatetime", TimeStampUtil.getNowDate());
            paraMap.put("osDate", dateString);
            //1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
            paraMap.put("osState", "1");
            paraMap.put("shopId", shopId);
            paraMap.put("shopName", forSettleShopInfo.getShopName());
            //结算订单类型 1-虚拟订单 2-实物订单',
            paraMap.put("osOrderType", "1");
            //罚款金额
            paraMap.put("osFineAmount", fineMoney.toString());
            //经销佣金
            paraMap.put("orderDealerCommission", "0");
            //供应商佣金
            paraMap.put("orderSupplyCommission", "0");
            //经销退还佣金
            paraMap.put("returnDealerCommission", "0");
            //供应商退还佣金
            paraMap.put("returnSupplyCommission", "0");

            Integer one = settleAccountsMapper.insertSettlement(paraMap);
            Map<String, String> updateMap = new HashMap<String, String>();
            updateMap.put("settlementOsId", osId);
            updateMap.put("shopId", shopId);
            updateMap.put("start", start);
            updateMap.put("end", end);
            updateMap.put("dropShipping", "2");
            Integer two = 0;
            if (null != orderIds && orderIds.size() > 0) {
                two = settleAccountsMapper.updateOrderBaseSettlement2(orderIds, osId);
            }
            Integer three = 0;
            if (null != returnOrderIds && returnOrderIds.size() > 0) {
                three = settleAccountsMapper.updateOrderReturnSettlement2(returnOrderIds, osId);
            }
            Integer four = settleAccountsMapper.updateShopComplainBase(paraMap);
            settleAccountsMapper.updateShopSettlement(shopId);
            logger.info("更新店铺：" + shopId + "插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two + " 更新退单表结算表个数" + three + "更新结束时间：" + TimeStampUtil.getNowDate());
        } catch (Exception e) {
            logger.info("异常============");
            e.printStackTrace();
        }
    }


    @Transactional(rollbackFor = Exception.class)
    public void settleDealerAccounts(ForSettleShopInfoDTO forSettleShopInfo) {
        try {
            Map<String, String> paraMap = new HashMap<>(16);

            String shopId = forSettleShopInfo.getShopId();

            logger.info("店铺" + shopId + "更新开始时间：" + TimeStampUtil.getNowDate());

            //格式化当前时间
            String end = DateUtils.getNowDayZero();
            //获取上次结算时间
            String dBefore = settleAccountsMapper.getBeformDate(shopId,2);
            if (org.springframework.util.StringUtils.isEmpty(dBefore)) {
                dBefore = "2021-05-01";
            }
            //格式化上次结算时间
            String start = dBefore + " 00:00:00";
            String dateString = TimeStampUtil.getYear() + TimeStampUtil.getMonth() + TimeStampUtil.getDay();

            Map<String, String> getMap = new HashMap<>(8);
            getMap.put("start", start);
            getMap.put("end", end);
            getMap.put("shopId", shopId);
            getMap.put("dropShipping", "1");
            //获取单个店铺所有未结算的订单。
            ShopSettleAccountInfoDTO orderSettleAccountOrder = settleAccountsMapper.getDealerSettleAccountOrder(getMap);

            //获取单个店铺所有未结算的退单
            ShopSettleAccountInfoDTO returnSettleAccountOrder = settleAccountsMapper.getDealerSettleAccountReturn(getMap);
            if(null == orderSettleAccountOrder){
                orderSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }
            if(null == returnSettleAccountOrder){
                returnSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }

            //没有订单没有退单直接返回
            if (null == orderSettleAccountOrder && null == returnSettleAccountOrder) {
                return;
            }
            //没有订单没有退单的情况
            if (null != orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "2" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", "0.00");//订单金额，不含运费
                paraMap.put("osShippingAmount", "0.00");//运费

                paraMap.put("osOrderReturnAmount", "0.00");//退单金额

                paraMap.put("osCommisAmount", "0.00");//佣金

                paraMap.put("osCommisReturnAmount", "0.00");//退还佣金

                paraMap.put("osRedpacketAmount", "0.00");//红包

                paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包

                //订单金额（不含运费）-供货价-抽佣+会员折扣+退还抽佣-退单金额（不含运费）+供货价-退还会员折扣
                Double osAmount = 0.00;

                paraMap.put("osAmount", osAmount.toString());//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "2");//结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osFineAmount", "0.00");//罚款金额
                paraMap.put("orderDealerCommission", "0.00");//经销佣金
                paraMap.put("orderSupplyCommission", "0");//供应商佣金
                paraMap.put("returnDealerCommission", "0");//经销退还佣金
                paraMap.put("returnSupplyCommission", "0");//供应商退还佣金
                paraMap.put("osBaseMemberDiscount", "0");//会员折扣
                paraMap.put("osReturnMemberDiscount", "0");//退还会员折扣
                paraMap.put("osSupplyPrice", "0");//供货价
                paraMap.put("osReturnSupplyPrice", "0");//退还供货价

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                logger.info(orderSettleAccountOrder.toString() + "更新店铺： " + shopId + "  插入结算表结果：" + one );
                return;
            }
            //有订单没有退单的情况
            if (null != orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "2" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));//订单金额，不含运费
                paraMap.put("osShippingAmount", String.valueOf(orderSettleAccountOrder.getOrderShippingFee()));//运费

                Double osOrderReturnAmount = 0.00;
                paraMap.put("osOrderReturnAmount", "0.00");//退单金额

                paraMap.put("osCommisAmount", orderSettleAccountOrder.getOrderCommissionFee().toString());//佣金

                Double returnCommission = 0.00;
                paraMap.put("osCommisReturnAmount", returnCommission.toString());//退还佣金
                paraMap.put("osRedpacketAmount", "0.00");//红包
                paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包


                //订单金额（不含运费）-供货价-抽佣+会员折扣+退还抽佣-退单金额（不含运费）+供货价-退还会员折扣
                Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount()
                        - orderSettleAccountOrder.getSupperPriceSum()
                        - orderSettleAccountOrder.getOrderCommissionFee()
                        + orderSettleAccountOrder.getBaseMemberDiscount();

                paraMap.put("osAmount", osAmount.toString());//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "2");//结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osFineAmount", "0.00");//罚款金额
                paraMap.put("orderDealerCommission", orderSettleAccountOrder.getOrderDealerCommission().doubleValue() + "");//经销佣金
                paraMap.put("orderSupplyCommission", "0");//供应商佣金
                paraMap.put("returnDealerCommission", "0");//经销退还佣金
                paraMap.put("returnSupplyCommission", "0");//供应商退还佣金
                paraMap.put("osBaseMemberDiscount", orderSettleAccountOrder.getBaseMemberDiscount().toString());//会员折扣
                paraMap.put("osReturnMemberDiscount", "0");//退还会员折扣
                paraMap.put("osSupplyPrice", orderSettleAccountOrder.getSupperPriceSum().toString());//供货价
                paraMap.put("osReturnSupplyPrice", "0");//退还供货价


                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, String> updateMap = new HashMap<>(8);
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                updateMap.put("dropShipping", "1");
                Integer two = settleAccountsMapper.updateOrderBaseSettlement(updateMap);
                logger.info(orderSettleAccountOrder.toString() + "更新店铺： " + shopId + "  插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two);
                return;
            }
            //没有订单 有退单
            if (null == orderSettleAccountOrder && null != returnSettleAccountOrder) {
                String osId = dateString + "2" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", orderSettleAccountOrder.getOrderPaymentAmount().toString());//订单金额，含运费
                paraMap.put("osShippingAmount", "0.00");//运费
                paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));//退单金额

                paraMap.put("osCommisAmount", "0.00");//佣金

                paraMap.put("osCommisReturnAmount", returnSettleAccountOrder.getOrderReturnCommissionFee().toString());//退还佣金
                paraMap.put("osRedpacketAmount", "0.00");//红包
                paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包

                //订单金额（不含运费）-供货价-抽佣+会员折扣+退还抽佣-退单金额（不含运费）+供货价-退还会员折扣
                Double osAmount = orderSettleAccountOrder.getOrderGoodsAmount()
                        + returnSettleAccountOrder.getOrderReturnCommissionFee()
                        - returnSettleAccountOrder.getReturnCash()
                        + returnSettleAccountOrder.getSupperReturnPrice()
                        - returnSettleAccountOrder.getReturnMemberDiscount();

                paraMap.put("osAmount", osAmount.toString());//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "2");//结算订单类型 1-虚拟订单 2-实物订单',

                paraMap.put("osFineAmount", "0.00");//罚款金额
                paraMap.put("orderDealerCommission", "0");//经销佣金
                paraMap.put("orderSupplyCommission", "0");//供应商佣金
                paraMap.put("returnDealerCommission", returnSettleAccountOrder.getReturnDealerCommission().doubleValue() + "");//经销退还佣金
                paraMap.put("returnSupplyCommission", "0");//供应商退还佣金
                paraMap.put("osBaseMemberDiscount", "0");//会员折扣
                paraMap.put("osReturnMemberDiscount", returnSettleAccountOrder.getReturnMemberDiscount().toString());//退还会员折扣
                paraMap.put("osSupplyPrice", "0");//供货价
                paraMap.put("osReturnSupplyPrice", returnSettleAccountOrder.getSupperReturnPrice().toString());//退还供货价


                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, String> updateMap = new HashMap<>(8);
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                updateMap.put("dropShipping", "1");
                Integer three = settleAccountsMapper.updateOrderReturnSettlement(updateMap);
                logger.info(returnSettleAccountOrder.toString() + "更新店铺：" + shopId + "插入结算表结果：" + one + three + "更新结束时间：" + TimeStampUtil.getNowDate());
                return;
            }
            //有订单有退单
            String osId = dateString + "2" + shopId;
            paraMap.put("osId", osId);
            paraMap.put("osStartDate", start);
            paraMap.put("osEndDate", end);
            paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));//订单金额，含运费
            paraMap.put("osShippingAmount", String.valueOf(orderSettleAccountOrder.getOrderShippingFee()));//运费
            paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));//退单金额

            paraMap.put("osCommisAmount",orderSettleAccountOrder.getOrderCommissionFee().toString());//佣金

            paraMap.put("osCommisReturnAmount", returnSettleAccountOrder.getOrderReturnCommissionFee().toString());//退还佣金

            paraMap.put("osRedpacketAmount", "0.00");//红包

            paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包


            //订单金额（不含运费）-供货价-抽佣+会员折扣+退还抽佣-退单金额（不含运费）+供货价-退还会员折扣
            Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount()
                    - orderSettleAccountOrder.getSupperPriceSum()
                    - orderSettleAccountOrder.getOrderCommissionFee()
                    + orderSettleAccountOrder.getBaseMemberDiscount()
                    + returnSettleAccountOrder.getOrderReturnCommissionFee()
                    - returnSettleAccountOrder.getReturnCash()
                    + returnSettleAccountOrder.getSupperReturnPrice()
                    - returnSettleAccountOrder.getReturnMemberDiscount();

            paraMap.put("osAmount", osAmount.toString());//应结算金额

            paraMap.put("osDatetime", TimeStampUtil.getNowDate());
            paraMap.put("osDate", dateString);
            paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
            paraMap.put("shopId", shopId);
            paraMap.put("shopName", forSettleShopInfo.getShopName());
            paraMap.put("osOrderType", "2");//结算订单类型 1-虚拟订单 2-实物订单',
            paraMap.put("osFineAmount", "0.00");//罚款金额

            paraMap.put("orderDealerCommission", orderSettleAccountOrder.getOrderDealerCommission().doubleValue() + "");//经销佣金
            paraMap.put("orderSupplyCommission", "0");//供应商佣金
            paraMap.put("returnDealerCommission", returnSettleAccountOrder.getReturnDealerCommission().doubleValue() + "");//经销退还佣金
            paraMap.put("returnSupplyCommission", "0");//供应商退还佣金
            paraMap.put("osBaseMemberDiscount", orderSettleAccountOrder.getBaseMemberDiscount().toString());//会员折扣
            paraMap.put("osReturnMemberDiscount", returnSettleAccountOrder.getReturnMemberDiscount().toString());//退还会员折扣
            paraMap.put("osSupplyPrice", orderSettleAccountOrder.getSupperPriceSum().toString());//供货价
            paraMap.put("osReturnSupplyPrice", returnSettleAccountOrder.getSupperReturnPrice().toString());//退还供货价


            Integer one = settleAccountsMapper.insertSettlement(paraMap);
            Map<String, String> updateMap = new HashMap<>(8);
            updateMap.put("settlementOsId", osId);
            updateMap.put("shopId", shopId);
            updateMap.put("start", start);
            updateMap.put("end", end);
            updateMap.put("dropShipping", "1");
            Integer two = settleAccountsMapper.updateOrderBaseSettlement(updateMap);
            Integer three = settleAccountsMapper.updateOrderReturnSettlement(updateMap);
            logger.info("更新店铺：" + shopId + "插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two + " 更新退单表结算表个数" + three + "更新结束时间：" + TimeStampUtil.getNowDate());
        } catch (Exception e) {
            logger.info("异常============");
            e.printStackTrace();
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void settleSupplyAccounts(ForSettleShopInfoDTO forSettleShopInfo) {
        try {
            String shopId = forSettleShopInfo.getShopId();

            logger.info("店铺" + shopId + "更新开始时间：" + TimeStampUtil.getNowDate());

            //格式化当前时间
            String end = DateUtils.getNowDayZero();
            //获取上次结算时间
            String dBefore = settleAccountsMapper.getBeformDate(shopId,3);
            if (org.springframework.util.StringUtils.isEmpty(dBefore)) {
                dBefore = "2021-05-01";
            }
            //格式化上次结算时间
            String start = dBefore + " 00:00:00";

            Map<String, String> getMap = new HashMap<>(8);
            getMap.put("start", start);
            getMap.put("end", end);
            getMap.put("shopId", shopId);
            getMap.put("dropShipping", "1");
            //获取单个店铺所有未结算的订单。
            ShopSettleAccountInfoDTO orderSettleAccountOrder = settleAccountsMapper.getSupplySettleAccountOrder(getMap);
            //获取单个店铺所有未结算的退单
            ShopSettleAccountInfoDTO returnSettleAccountOrder = settleAccountsMapper.getSupplySettleAccountReturn(getMap);
            // 需要结算的退款订单编码
            List<String> orderIdList = settleAccountsMapper.querySupplyOrderBaseInfo(getMap);

            if(null == orderSettleAccountOrder){
                orderSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }
            if(null == returnSettleAccountOrder){
                returnSettleAccountOrder = new ShopSettleAccountInfoDTO();
            }

            //获取单个店铺普通订单分佣总价
            Double paymentAmounCats = orderSettleAccountOrder.getOrderCommissionFee();

            //获取单个店铺普通订单 退单 分佣总价
            Double refundPaymentAmounCats = returnSettleAccountOrder.getOrderReturnCommissionFee();

            //供应商经销等级 折扣
            Double supperDiscountFee = orderSettleAccountOrder.getSupperDiscountFee();
            //退还 供应商经销等级 折扣
            Double returnSupperDiscountFee = returnSettleAccountOrder.getReturnSupperDiscountFee();

            String dateString = TimeStampUtil.getYear() + TimeStampUtil.getMonth() + TimeStampUtil.getDay();
            Map<String, String> paraMap = new HashMap<>(16);
            if (null == orderSettleAccountOrder && null == returnSettleAccountOrder) {
                //直接返回
                return;
            }
            //没有订单没有退单
            if (null != orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "3" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", "0.00");//订单金额，含运费
                paraMap.put("osShippingAmount", "0.00");//运费

                paraMap.put("osOrderReturnAmount", "0.00");//退单金额

                Double commission = 0.00;
                paraMap.put("osCommisAmount", commission.toString());//佣金
                Double returnCommission = 0.00;
                paraMap.put("osCommisReturnAmount", returnCommission.toString());//退还佣金
                paraMap.put("osCommisReturnAmount", "0.00");//退还佣金
                paraMap.put("osRedpacketAmount", "0.00");//红包
                paraMap.put("osSupperDiscountFee", "0.00");//供应商经销等级 折扣
                paraMap.put("osReturnSupperDiscountFee", "0.00");//供应商退还经销等级折扣

                paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包

                paraMap.put("osAmount", "0.00");//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "3");//结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osFineAmount", "0.00");//罚款金额

                paraMap.put("orderDealerCommission", "0");//经销佣金
                paraMap.put("orderSupplyCommission", "0");//供应商佣金
                paraMap.put("returnDealerCommission", "0");//经销退还佣金
                paraMap.put("returnSupplyCommission", "0");//供应商退还佣金

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                logger.info(orderSettleAccountOrder.toString() + "更新店铺： " + shopId + "  插入结算表结果：" + one );
                return;
            }
            //有订单没有退单的情况
            if (null != orderSettleAccountOrder && null == returnSettleAccountOrder) {
                String osId = dateString + "3" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));//订单金额，不含运费
                paraMap.put("osShippingAmount", orderSettleAccountOrder.getOrderShippingFee().toString());//运费

                paraMap.put("osOrderReturnAmount", "0.00");//退单金额

                paraMap.put("osCommisAmount", paymentAmounCats.toString());//佣金
                Double returnCommission = 0.00;
                paraMap.put("osCommisReturnAmount", returnCommission.toString());//退还佣金

                paraMap.put("osSupperDiscountFee", supperDiscountFee.toString());//供应商经销等级 折扣
                paraMap.put("osReturnSupperDiscountFee", "0.00");//供应商退还经销等级折扣
                paraMap.put("osRedpacketAmount", "0.00");//红包

                paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包

                //供货价+运费-抽佣-退单（供货价）+退还抽佣-经销商等级折扣+退还经销商等级折扣
                Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount()
                        - supperDiscountFee
                        - paymentAmounCats
                        + orderSettleAccountOrder.getOrderShippingFee();

                paraMap.put("osAmount", osAmount.toString());//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "3");//结算订单类型 1-虚拟订单 2-实物订单',
                paraMap.put("osFineAmount", "0.00");//罚款金额

                paraMap.put("orderDealerCommission", "0");//经销佣金
                paraMap.put("orderSupplyCommission", orderSettleAccountOrder.getOrderSupplyCommission().doubleValue() + "");//供应商佣金
                paraMap.put("returnDealerCommission", "0");//经销退还佣金
                paraMap.put("returnSupplyCommission", "0");//供应商退还佣金

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, Object> updateMap = new HashMap<>(8);
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                Integer two = settleAccountsMapper.updateSupplyOrderBaseSettlement(updateMap);
                logger.info(orderSettleAccountOrder.toString() + "更新店铺： " + shopId + "  插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two);
                return;
            }
            //没有订单 有退单
            if (null == orderSettleAccountOrder && null != returnSettleAccountOrder) {
                String osId = dateString + "3" + shopId;
                paraMap.put("osStartDate", start);
                paraMap.put("osEndDate", end);

                paraMap.put("osId", osId);
                paraMap.put("orderPaymentAmount", "0.00");//订单金额，含运费
                paraMap.put("osShippingAmount", "0.00");//运费
                paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));//退单金额

                Double commission = 0.00;
                paraMap.put("osCommisAmount", commission.toString());//佣金

                paraMap.put("osCommisReturnAmount", refundPaymentAmounCats.toString());//退还佣金

                paraMap.put("osSupperDiscountFee", "0.00");//供应商经销等级 折扣
                paraMap.put("osReturnSupperDiscountFee", returnSupperDiscountFee.toString());//供应商退还经销等级折扣

                Double osRedpacketAmount = 0.00;
                paraMap.put("osRedpacketAmount", osRedpacketAmount.toString());//红包

                Double osRedpacketReturnAmount = 0.00;
                paraMap.put("osRedpacketReturnAmount", osRedpacketReturnAmount.toString());//退还红包

                //供货价+运费-抽佣-退单（供货价）+退还抽佣-经销商等级折扣+退还经销商等级折扣
                Double osAmount =  orderSettleAccountOrder.getOrderPaymentAmount()
                        - returnSettleAccountOrder.getReturnCash()
                        + refundPaymentAmounCats
                        + returnSupperDiscountFee;

                paraMap.put("osAmount", osAmount.toString());//应结算金额

                paraMap.put("osDatetime", TimeStampUtil.getNowDate());
                paraMap.put("osDate", dateString);
                paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
                paraMap.put("shopId", shopId);
                paraMap.put("shopName", forSettleShopInfo.getShopName());
                paraMap.put("osOrderType", "3");//结算订单类型 1-虚拟订单 2-实物订单',

                paraMap.put("osFineAmount", "0.00");//罚款金额

                paraMap.put("orderDealerCommission", "0");//经销佣金
                paraMap.put("orderSupplyCommission", "0");//供应商佣金
                paraMap.put("returnDealerCommission", "0");//经销退还佣金
                paraMap.put("returnSupplyCommission", returnSettleAccountOrder.getReturnSupplyCommission().doubleValue() + "");//供应商退还佣金

                Integer one = settleAccountsMapper.insertSettlement(paraMap);
                Map<String, Object> updateMap = new HashMap<>(8);
                updateMap.put("settlementOsId", osId);
                updateMap.put("shopId", shopId);
                updateMap.put("start", start);
                updateMap.put("end", end);
                updateMap.put("orderIdList", orderIdList);
                Integer three = 0;
                if(!orderIdList.isEmpty()) {
                    three = settleAccountsMapper.updateSupplyOrderReturnSettlement(updateMap);
                }
                logger.info(returnSettleAccountOrder.toString() + "更新店铺：" + shopId + "插入结算表结果：" + one + " 更新退单表结算表个数" + three + "更新结束时间：" + TimeStampUtil.getNowDate());

                return;
            }
            //有订单有退单
            String osId = dateString + "3" + shopId;
            paraMap.put("osId", osId);
            paraMap.put("osStartDate", start);
            paraMap.put("osEndDate", end);
            paraMap.put("orderPaymentAmount", String.valueOf(orderSettleAccountOrder.getOrderPaymentAmount()));//订单金额，含运费
            paraMap.put("osShippingAmount", orderSettleAccountOrder.getOrderShippingFee().toString());//运费
            paraMap.put("osOrderReturnAmount", String.valueOf(returnSettleAccountOrder.getReturnCash()));//退单金额

            paraMap.put("osCommisAmount", paymentAmounCats.toString());//佣金
            paraMap.put("osCommisReturnAmount", refundPaymentAmounCats.toString());//退还佣金

            paraMap.put("osSupperDiscountFee", supperDiscountFee.toString());//供应商经销等级 折扣
            paraMap.put("osReturnSupperDiscountFee", returnSupperDiscountFee.toString());//供应商退还经销等级折扣

            paraMap.put("osRedpacketAmount", "0.00");//红包

            paraMap.put("osRedpacketReturnAmount", "0.00");//退还红包

            ///供货价+运费-抽佣-退单（供货价）+退还抽佣-经销商等级折扣+退还经销商等级折扣
            Double osAmount = orderSettleAccountOrder.getOrderPaymentAmount()
                    - paymentAmounCats
                    + orderSettleAccountOrder.getOrderShippingFee()
                    - returnSettleAccountOrder.getReturnCash()
                    + refundPaymentAmounCats;

            paraMap.put("osAmount", osAmount.toString());//应结算金额

            paraMap.put("osDatetime", TimeStampUtil.getNowDate());
            paraMap.put("osDate", dateString);
            paraMap.put("osState", "1");//1默认(已出账)2店家已确认3平台已审核4结算完成 5已提现',
            paraMap.put("shopId", shopId);
            paraMap.put("shopName", forSettleShopInfo.getShopName());
            paraMap.put("osOrderType", "3");//结算订单类型 1-虚拟订单 2-实物订单',
            paraMap.put("osFineAmount", "0.00");//罚款金额

            paraMap.put("orderDealerCommission", orderSettleAccountOrder.getOrderCommissionFee()+"");//经销佣金
            paraMap.put("orderSupplyCommission", orderSettleAccountOrder.getOrderSupplyCommission() + "");//供应商佣金
            paraMap.put("returnDealerCommission", returnSettleAccountOrder.getOrderReturnCommissionFee() + "");//经销退还佣金
            paraMap.put("returnSupplyCommission", returnSettleAccountOrder.getReturnSupplyCommission() + "");//供应商退还佣金

            Integer one = settleAccountsMapper.insertSettlement(paraMap);
            Map<String, Object> updateMap = new HashMap<>(8);
            updateMap.put("settlementOsId", osId);
            updateMap.put("shopId", shopId);
            updateMap.put("start", start);
            updateMap.put("end", end);
            updateMap.put("orderIdList", orderIdList);
            Integer two = settleAccountsMapper.updateSupplyOrderBaseSettlement(updateMap);
            Integer three = 0;
            if(!orderIdList.isEmpty()) {
                three = settleAccountsMapper.updateSupplyOrderReturnSettlement(updateMap);
            }
            logger.info("更新店铺：" + shopId + "插入结算表结果：" + one + " 更新orderbase表待结算订单个数：" + two + " 更新退单表结算表个数" + three + "更新结束时间：" + TimeStampUtil.getNowDate());
        } catch (Exception e) {
            logger.info("异常============");
            e.printStackTrace();
        }
    }

}
